package org.example.controller;


import org.example.common.R;
import org.example.pojo.entity.ApComment;
import org.example.pojo.vo.CommentVo;
import org.example.service.IApCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-26
 */
@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/front/comment")
public class ApCommentController {

    @Autowired
    private IApCommentService apCommentService;

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @PostMapping
    public R addComment(@RequestBody ApComment comment) {
        apCommentService.addComment(comment);
        return R.ok("评论成功");
    }

    /**
     * 递归获取评论列表
     *
     * @param newsId
     * @param commentId
     * @return
     */
    @GetMapping("/list")
    public R getCommentList(@RequestParam String newsId, @RequestParam String commentId) {
        return apCommentService.getCommentList(newsId, commentId);
    }


    /**
     * 获取一级评论列表
     *
     * @param newsId
     * @return
     */
    @GetMapping("/first")
    public R getCommentFirstList(@RequestParam String newsId) {
        List<CommentVo> commentFirstList = apCommentService.getCommentFirstList(newsId);
        return R.ok(commentFirstList);
    }
}
